<script setup lang="ts">
import { useDicomDataStore } from "@renderer/store/pinia/dicomData";
import { postRequest } from "@renderer/api/request";
import { EnumViewMode, EnumViewType } from "@renderer/assets/types";
import API from "@renderer/api/api";
import { useTabManagerStore } from "@renderer/store/pinia/tabManager";
import { useSystemSettingStore } from "@renderer/store/pinia/systemSetting";
import {inject} from 'vue';
import BaseIcon from "@renderer/assets/icon/BaseIcon.vue";

const dicomDataStore = useDicomDataStore();
const tabStore = useTabManagerStore();
const {
  folderLoadingVisible
} = inject('seriesListOp') as any;

const handleOpen = async () => {
  const folderPath = await (window as any).folderApi.selectFolder()
  const relativePath = folderPath.split("\\").slice(2).join('\\');
  console.log('folderPath', folderPath.split("\\"), relativePath);
  if (!folderPath){
    return;
  }
  folderLoadingVisible.value = true;
  const ans = await postRequest(API.resolveFolder,{
    relativePath
  })
  const {
    patientRecord, seriesRecord
  } = ans.data
  dicomDataStore.updatePatientAndSeriesRecord(patientRecord, seriesRecord)
  folderLoadingVisible.value = false;
};

const chooseViewType = (viewMode,viewType) => tabStore.selectViewType(viewMode, viewType)
const systemStore = useSystemSettingStore()
</script>

<template>
  <header class="w-full h-[35px] flex position-relative">
    <v-btn height="100%" :disabled="!systemStore.connectState"
           size="small" class="flex-1"
           @click="handleOpen">
      <v-icon icon="mdi-folder" size="26"></v-icon>
    </v-btn>

    <v-btn height="100%"  class="flex-1" size="small"  @click="chooseViewType(EnumViewMode.quick, EnumViewType.stack)">
      <v-icon icon="mdi-lightning-bolt" size="26"></v-icon>
    </v-btn>

    <v-btn height="100%" disabled  class="flex-1" size="small"   @click="chooseViewType(EnumViewMode.normal,EnumViewType.threeD)">
      <v-icon icon="mdi-cube-outline" size="26"></v-icon>
    </v-btn>

    <v-btn height="100%"  class="flex-1" size="small" @click="chooseViewType(EnumViewMode.normal,EnumViewType.mpr)">
        <base-icon name="cubeIcon"></base-icon>
    </v-btn>

  </header>
</template>

<style scoped></style>
